package com.me.customerdemo.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.me.customerdemo.dao.UserMapper;
import com.me.customerdemo.pojo.User;
import com.me.customerdemo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServerImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public PageInfo<User> findByKeyword(int pageNum, int pageSize, String keyword) {
        PageHelper.startPage(pageNum,pageSize);
        List<User> users = userMapper.selectByKeyowrd(keyword);
        PageInfo<User> pageInfo = new PageInfo<>(users);
        return pageInfo;
    }

    @Override
    public User selectByNamePassWord(String name, String password) {
        return userMapper.selectByNamePassWord(name,password);
    }

    @Override
    public List<User> selectAll() {
        return userMapper.selectAll();
    }

    @Override
    public boolean updateById(User user) {
        return userMapper.updateById(user)>0? true:false;
    }

    @Override
    public boolean deleteById(int id) {
        return userMapper.deleteById(id)>0?true:false;
    }

    @Override
    public boolean apply(User user) {
        return userMapper.apply(user)>0?true:false;
    }

    @Override
    public User selectById(int id) {
        return userMapper.selectById(id);
    }
}
